// https://leetcode.cn/problems/sum-of-subsequence-widths/
// Created by ade on 2022/11/18.
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int sumSubseqWidths(vector<int> &nums) {
        int MOD = 1e9 + 7;
        int n = nums.size();
        vector<long> powArr(n, 1);
        for (int i = 1; i < n; i++)
            powArr[i] = powArr[i - 1] * 2 % MOD;

        long res = 0;
        for (int i = 0; i < n; i++) {
            res = (res + (powArr[i] - powArr[n - 1 - i]) * nums[i] % MOD) % MOD;
        }
        return res;
    }
};

int main() {
    Solution so;
    vector<int> nums = {1, 2, 3};
    cout << so.sumSubseqWidths(nums) << endl;
    return 0;
}